<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="jypath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="${jypath}/static/css/system/bootstrap/bootstrap.min.css"/>
		<script type="text/javascript" src="${jypath}/static/js/jquery/jquery-2.0.3.min.js"></script>
		<script type="text/javascript" src="${jypath}/static/plugins/layer/2.1/layer.js"></script>
	</head>
	<body>
		<div class="container">
			<div class="row">
			    <div class="col-xs-offset-1 col-xs-10">
				<form class="form-horizontal" id="distributionForm">
				    <input type="hidden" id="callCustomerids" value="${ids}"/>
					<div class="form-group">
						<label class="col-xs-2 control-label"><font style="color:red">*</font>角色:</label>
						<div class="col-xs-8">
							<select class="form-control" id="roleId" onchange="loadRoleUser()">
								<option value="">全部</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-2 control-label"><font style="color:red">*</font>用户:</label>
						<div class="col-xs-8">
							<select class="form-control" id="userId">
								<option value="">全部</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<div class="col-xs-6">
						</div>
						<div class="col-xs-6">
							<button type="button" class="btn btn-default" onclick="saveDistribution()">确定</button>
							<button type="button" class="btn btn-default" onclick="canelDistribution()">取消</button>
						</div>
									
					</div>
				</form>
				</div>
			</div>
		</div>
	</body>
<script type="text/javascript">
var layerIndex = parent.layer.getFrameIndex(window.name); 
$(function () {
	loadAllRole();
});
function canelDistribution(){
	 parent.layer.close(layerIndex);
}
function saveDistribution(){
	var userId=$("#userId").val();
	var callCustomerids=$("#callCustomerids").val();
	if(userId==null || userId==""){
		layer.alert('用户必选')
		return;
	}
	$.ajax({
		type: 'post',
        url: "${jypath}/call/callCustomer/saveDistribution",
	    data: {
	    	userId:userId,
	    	ids:callCustomerids
	    },
	    dataType:'json',
	    async: false,
	    success: function(data){
	    	if(data.res=="1"){
/* 	    		layer.confirm("分配成功", {
		    		   btn: ['确定'] //按钮
		    		}, function(index){
		    			parent.getbaseList(1);
		    			//canelDistribution();
		    	}); */
		    	parent.getbaseList(1);
		    	parent.layer.closeAll();
	    		
	    		
	    	}else if(data.res=="100"){
	    		layer.alert("权限不足！")
	    	}else{
	    		layer.alert(data.resMsg);
	    	}
	    	
	    	
	    }
	});
	
}
function loadAllRole(){
	$.ajax({
		type: 'post',
        url: "${jypath}/system/role/listAll",
	    data: {},
	    dataType:'json',
	    async: false,
	    success: function(data){
			var obj=data.obj;
			var allRole='<option value="-1">请选择</option>';
			$.each(obj,function(n,v) {
				allRole=allRole+'<option value="'+v.id+'">'+v.roleName+'</option>';
			});
			$("#roleId").empty();
			$("#roleId").append(allRole);
	    	
	    }
	});
}

function loadRoleUser(){
	var roleId=$("#roleId").val();
	if(null==roleId || roleId==""){
		$("#userId").empty();
		return;
	}
	$.ajax({
		type: 'post',
        url: "${jypath}/system/user/findRoleUser",
	    data: {
	    	roleId:roleId
	    },
	    dataType:'json',
	    async: false,
	    success: function(data){
	    	var obj=data.obj;
			var allRole='';
			$.each(obj,function(n,v) {
				allRole=allRole+'<option value="'+v.id+'">'+v.userName+'</option>';
			});
			$("#userId").empty();
			$("#userId").append(allRole);
	    }
	});
	
}
</script>
</html>